package org.llw.ldailytask.ui;

import java.util.ArrayList;
import java.util.Random;
import org.llw.ldailytask.R;
import org.llw.ldailytask.util.SlideAdapter;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.roamer.slidelistview.SlideListView;

public class ListFragment extends Fragment {
	private SlideAdapter mAdapter;
	private ArrayList<String> mTestData;
	private SlideListView mSlideListView;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_list, container, false);
		mTestData = new ArrayList<String>();
		randomCreateTestData();
		
	    //mAdapter = new SlideAdapter(getActivity(), mTestData);
		mSlideListView = (SlideListView) v.findViewById(R.id.task_list_view);		
		mSlideListView.setAdapter(mAdapter);
		
		return v;

//		TextView headView1 = new TextView(MyApplication.getInstance());
//		headView1.setHeight(60);
//		TextView headView2 = new TextView(MyApplication.getInstance());
//		headView2.setHeight(60);
//		TextView footerView1 = new TextView(MyApplication.getInstance());
//		footerView1.setHeight(60);
//		headView1.setText("这是HeaderView1");
//		headView2.setText("这是HeaderView2");
//		footerView1.setText("这是FooterView1");
//		mSlideListView.addHeaderView(headView1);
//		mSlideListView.addHeaderView(headView2);
//		mSlideListView.addFooterView(footerView1);

   
//		mSlideListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//				String s = (String) parent.getAdapter().getItem(position);
//				if (!TextUtils.isEmpty(s)) {
//					Toast.makeText(MyApplication.getInstance(), "OnItemClick:" + s, Toast.LENGTH_SHORT).show();
//				}
//			}
//		});
//		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	Random random = new Random();
	private void randomCreateTestData() {
		mTestData.clear();
		int length = random.nextInt(100);
		for (int i = 0; i < length; i++) {
			mTestData.add(getRandomString());
		}
	}

	private String getRandomString() {
		int length = random.nextInt(20);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < length; i++) {
			sb.append((char) (random.nextInt(26) + 97));
		}
		return sb.toString();
	}
	
}
